<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>AutoDiscovery - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.soap.autodiscovery.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.soap.autodiscovery.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.soap.wsdl.html">WSDL Accessor</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.soap.html">Zend_Soap</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.tag.html">Zend_Tag</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.soap.autodiscovery" class="section"><div class="info"><h1 class="title">AutoDiscovery</h1></div>
    

    <div class="section" id="zend.soap.autodiscovery.introduction"><div class="info"><h1 class="title">AutoDiscovery Introduction</h1></div>
        

        <p class="para">
            <acronym class="acronym">SOAP</acronym> functionality implemented within Zend Framework is intended to
            make all steps required for <acronym class="acronym">SOAP</acronym> communications more simple.
        </p>

        <p class="para">
            <acronym class="acronym">SOAP</acronym> is language independent protocol. So it may be used not only for
            <acronym class="acronym">PHP</acronym>-to-PHP communications.
        </p>

        <p class="para">
            There are three configurations for <acronym class="acronym">SOAP</acronym> applications where Zend
            Framework may be utilized:

            <ol type="1">
                <li class="listitem">
                    <span class="simpara">
                        SOAP server <acronym class="acronym">PHP</acronym> application &lt;---&gt;
                        <acronym class="acronym">SOAP</acronym> client <acronym class="acronym">PHP</acronym> application
                    </span>
                </li>

                <li class="listitem">
                    <span class="simpara">
                        SOAP server non-PHP application &lt;---&gt; <acronym class="acronym">SOAP</acronym>
                        client <acronym class="acronym">PHP</acronym> application
                    </span>
                </li>

                <li class="listitem">
                    <span class="simpara">
                        SOAP server <acronym class="acronym">PHP</acronym> application &lt;---&gt;
                        <acronym class="acronym">SOAP</acronym> client non-PHP application
                    </span>
                </li>
            </ol>
        </p>

        <p class="para">
            We always have to know, which functionality is provided by <acronym class="acronym">SOAP</acronym>
            server to operate with it. <a href="http://www.w3.org/TR/wsdl" class="link external">&raquo; WSDL</a> is used
            to describe network service <acronym class="acronym">API</acronym> in details.
        </p>

        <p class="para">
            WSDL language is complex enough (see <a href="http://www.w3.org/TR/wsdl" class="link external">&raquo; http://www.w3.org/TR/wsdl</a>
            for the details). So it&#039;s difficult to prepare correct WSDL description.
        </p>

        <p class="para">
            Another problem is synchronizing changes in network service <acronym class="acronym">API</acronym> with
            already existing WSDL.
        </p>

        <p class="para">
            Both these problem may be solved by WSDL autogeneration. A prerequisite for this is a
            <acronym class="acronym">SOAP</acronym> server autodiscovery. It constructs object similar to object
            used in <acronym class="acronym">SOAP</acronym> server application, extracts necessary information and
            generates correct WSDL using this information.
        </p>

        <p class="para">
            There are two ways for using Zend Framework for <acronym class="acronym">SOAP</acronym> server
            application:

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">Use separated class.</p>
                </li>

                <li class="listitem">
                    <p class="para">Use set of functions</p>
                </li>
            </ul>
        </p>

        <p class="para">
            Both methods are supported by Zend Framework Autodiscovery functionality.
        </p>

        <p class="para">
            The<span class="classname">Zend_Soap_AutoDiscover</span> class also supports datatypes mapping
            from <acronym class="acronym">PHP</acronym> to <a href="http://www.w3.org/TR/xmlschema-2/" class="link external">&raquo; XSD types</a>.
        </p>

        <p class="para">
            Here is an example of common usage of the autodiscovery functionality. The
             <span class="methodname">handle()</span> function generates the WSDL file and posts it to the
            browser.
        </p>

        <pre class="programlisting brush: php">
class My_SoapServer_Class {
...
}

$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover-&gt;setClass(&#039;My_SoapServer_Class&#039;);
$autodiscover-&gt;handle();
</pre>


        <p class="para">
            If you need access to the generated WSDL file either to save it to a file or as an
            <acronym class="acronym">XML</acronym> string you can use the  <span class="methodname">dump($filename)</span>
            or  <span class="methodname">toXml()</span> functions the AutoDiscover class provides.
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Zend_Soap_Autodiscover is not a Soap Server</b><br /></span>
            

            <p class="para">
                It is very important to note, that the class
                <span class="classname">Zend_Soap_AutoDiscover</span> does not act as a
                <acronym class="acronym">SOAP</acronym> Server on its own. It only generates the WSDL and serves it
                to anyone accessing the url it is listening on.
            </p>

            <p class="para">
                As the <acronym class="acronym">SOAP</acronym> Endpoint Uri is uses the default
                <code class="code">&#039;http://&#039; .$_SERVER[&#039;HTTP_HOST&#039;] . $_SERVER[&#039;SCRIPT_NAME&#039;]</code>, but this
                can be changed with the  <span class="methodname">setUri()</span> function or the
                Constructor parameter of <span class="classname">Zend_Soap_AutoDiscover</span> class. The
                endpoint has to provide a <span class="classname">Zend_Soap_Server</span> that listens to
                requests.
            </p>

            <pre class="programlisting brush: php">
if(isset($_GET[&#039;wsdl&#039;])) {
    $autodiscover = new Zend_Soap_AutoDiscover();
    $autodiscover-&gt;setClass(&#039;HelloWorldService&#039;);
    $autodiscover-&gt;handle();
} else {
    // pointing to the current file here
    $soap = new Zend_Soap_Server(&quot;http://example.com/soap.php?wsdl&quot;);
    $soap-&gt;setClass(&#039;HelloWorldService&#039;);
    $soap-&gt;handle();
}
</pre>

        </p></blockquote>
    </div>

    <div class="section" id="zend.soap.autodiscovery.class"><div class="info"><h1 class="title">Class autodiscovering</h1></div>
        

        <p class="para">
            If class is used to provide SOAP server functionality, then the same class should be
            provided to <span class="classname">Zend_Soap_AutoDiscover</span> for WSDL generation:
        </p>

        <pre class="programlisting brush: php">
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover-&gt;setClass(&#039;My_SoapServer_Class&#039;);
$autodiscover-&gt;handle();
</pre>


        <p class="para">
            The following rules are used while WSDL generation:

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">Generated WSDL describes an RPC style Web Service.</p>
                </li>

                <li class="listitem">
                    <p class="para">Class name is used as a name of the Web Service being described.</p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <code class="code">&#039;http://&#039; .$_SERVER[&#039;HTTP_HOST&#039;] . $_SERVER[&#039;SCRIPT_NAME&#039;]</code> is
                        used as an <acronym class="acronym">URI</acronym> where the WSDL is available by default but
                        can be overwritten via  <span class="methodname">setUri()</span> method.
                    </p>

                    <p class="para">
                         It&#039;s also used as a target namespace for all service related names
                         (including described complex types).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Class methods are joined into one <a href="http://www.w3.org/TR/wsdl#_porttypes" class="link external">&raquo; Port Type</a>.
                    </p>

                    <p class="para">
                        <code class="code">$className . &#039;Port&#039;</code> is used as Port Type name.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">Each class method is registered as a corresponding port operation.</p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Each method prototype generates corresponding Request/Response messages.
                    </p>

                    <p class="para">
                        Method may have several prototypes if some method parameters are optional.
                    </p>
                </li>
            </ul>
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Important!</b><br /></span>
            

            <p class="para">
                WSDL autodiscovery utilizes the <acronym class="acronym">PHP</acronym> docblocks provided by the
                developer to determine the parameter and return types. In fact, for scalar types,
                this is the only way to determine the parameter types, and for return types, this is
                the only way to determine them.
            </p>

            <p class="para">
                That means, providing correct and fully detailed docblocks is not only best
                practice, but is required for discovered class.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.soap.autodiscovery.functions"><div class="info"><h1 class="title">Functions autodiscovering</h1></div>
        

        <p class="para">
            If set of functions are used to provide SOAP server functionality, then the same set
            should be provided to <span class="classname">Zend_Soap_AutoDiscovery</span> for WSDL
            generation:
        </p>

        <pre class="programlisting brush: php">
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover-&gt;addFunction(&#039;function1&#039;);
$autodiscover-&gt;addFunction(&#039;function2&#039;);
$autodiscover-&gt;addFunction(&#039;function3&#039;);
...
$autodiscover-&gt;handle();
</pre>


        <p class="para">
            The following rules are used while WSDL generation:

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">Generated WSDL describes an RPC style Web Service.</p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Current script name is used as a name of the Web Service being described.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <code class="code">&#039;http://&#039; .$_SERVER[&#039;HTTP_HOST&#039;] . $_SERVER[&#039;SCRIPT_NAME&#039;]</code> is
                        used as an <acronym class="acronym">URI</acronym> where the WSDL is available.
                    </p>

                    <p class="para">
                         It&#039;s also used as a target namespace for all service related names
                         (including described complex types).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Functions are joined into one <a href="http://www.w3.org/TR/wsdl#_porttypes" class="link external">&raquo; Port Type</a>.
                    </p>

                    <p class="para">
                        <code class="code">$functionName . &#039;Port&#039;</code> is used as Port Type name.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">Each function is registered as a corresponding port operation.</p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Each function prototype generates corresponding Request/Response messages.
                    </p>

                    <p class="para">
                        Function may have several prototypes if some method parameters are optional.
                    </p>
                </li>
            </ul>
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Important!</b><br /></span>
            

            <p class="para">
                WSDL autodiscovery utilizes the <acronym class="acronym">PHP</acronym> docblocks provided by the
                developer to determine the parameter and return types. In fact, for scalar types,
                this is the only way to determine the parameter types, and for return types, this is
                the only way to determine them.
            </p>

            <p class="para">
                That means, providing correct and fully detailed docblocks is not only best
                practice, but is required for discovered class.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.soap.autodiscovery.datatypes"><div class="info"><h1 class="title">Autodiscovering Datatypes</h1></div>
        

        <p class="para">
            Input/output datatypes are converted into network service types using the following
            mapping:

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">PHP strings &lt;-&gt; <code class="code">xsd:string</code>.</p>
                </li>

                <li class="listitem">
                    <p class="para">PHP integers &lt;-&gt; <code class="code">xsd:int</code>.</p>
                </li>

                <li class="listitem">
                    <p class="para">PHP floats and doubles &lt;-&gt; <code class="code">xsd:float</code>.</p>
                </li>

                <li class="listitem">
                    <p class="para">PHP booleans &lt;-&gt; <code class="code">xsd:boolean</code>.</p>
                </li>

                <li class="listitem">
                    <p class="para">PHP arrays &lt;-&gt; <code class="code">soap-enc:Array</code>.</p>
                </li>

                <li class="listitem">
                    <p class="para">PHP object &lt;-&gt; <code class="code">xsd:struct</code>.</p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <acronym class="acronym">PHP</acronym> class &lt;-&gt; based on complex type strategy (See:
                        <a href="zend.soap.wsdl.html#zend.soap.wsdl.types.add_complex" class="link">this section</a>)

                        <a href="#fnid1" name="fn1"><sup>[1]</sup></a>
                            
                                <span class="classname">Zend_Soap_AutoDiscover</span><span class="classname">Zend_Soap_Wsdl_Strategy_DefaultComplexType</span><span class="classname">Zend_Soap_Wsdl_Strategy_Interface</span><var class="varname">$extractComplexType</var><span class="classname">Zend_Soap_Wsdl</span><a href="zend.soap.wsdl.html#zend.soap.wsdl.types.add_complex" class="link"><span class="classname">Zend_Soap_Wsdl</span>
                                    manual on adding complex</a>
                        .
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        type[] or object[] (ie. int[]) &lt;-&gt; based on complex type strategy
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">PHP void &lt;-&gt; empty type.</p>
                </li>

                <li class="listitem">
                    <p class="para">
                        If type is not matched to any of these types by some reason, then
                        <code class="code">xsd:anyType</code> is used.
                    </p>
                </li>
            </ul>

            Where <code class="code">xsd:</code> is &quot;http://www.w3.org/2001/XMLSchema&quot; namespace,
            <code class="code">soap-enc:</code> is a &quot;http://schemas.xmlsoap.org/soap/encoding/&quot; namespace,
            <code class="code">tns:</code> is a &quot;target namespace&quot; for a service.
        </p>
    </div>

    <div class="section" id="zend.soap.autodiscovery.wsdlstyles"><div class="info"><h1 class="title">WSDL Binding Styles</h1></div>
        

        <p class="para">
            WSDL offers different transport mechanisms and styles. This affects the
            <code class="code">soap:binding</code> and <code class="code">soap:body</code> tags within the Binding
            section of WSDL. Different clients have different requirements as to what options
            really work. Therefore you can set the styles before you call any <code class="code">setClass</code>
            or <code class="code">addFunction</code> method on the AutoDiscover class.
        </p>

        <pre class="programlisting brush: php">
$autodiscover = new Zend_Soap_AutoDiscover();
// Default is &#039;use&#039; =&gt; &#039;encoded&#039; and
// &#039;encodingStyle&#039; =&gt; &#039;http://schemas.xmlsoap.org/soap/encoding/&#039;
$autodiscover-&gt;setOperationBodyStyle(
                    array(&#039;use&#039; =&gt; &#039;literal&#039;,
                          &#039;namespace&#039; =&gt; &#039;http://framework.zend.com&#039;)
                );

// Default is &#039;style&#039; =&gt; &#039;rpc&#039; and
// &#039;transport&#039; =&gt; &#039;http://schemas.xmlsoap.org/soap/http&#039;
$autodiscover-&gt;setBindingStyle(
                    array(&#039;style&#039; =&gt; &#039;document&#039;,
                          &#039;transport&#039; =&gt; &#039;http://framework.zend.com&#039;)
                );
...
$autodiscover-&gt;addFunction(&#039;myfunc1&#039;);
$autodiscover-&gt;handle();
</pre>

    </div>
<div class="footnote"><a name="fnid1" href="#fn1"><sup>[1]</sup></a><span class="para footnote"> will be created with
                                the
                                
                                class as detection algorithm for complex types. The first parameter
                                of the AutoDiscover constructor takes any complex type strategy
                                implementing
                                 or a string
                                with the name of the class. For backwards compatibility with
                                 boolean variables are parsed
                                exactly like in . See the
                                 types for more information.
                            </span></div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.soap.wsdl.html">WSDL Accessor</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.soap.html">Zend_Soap</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.tag.html">Zend_Tag</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.soap.html">Zend_Soap</a></li>
  <li><a href="zend.soap.server.html">Zend_Soap_Server</a></li>
  <li><a href="zend.soap.client.html">Zend_Soap_Client</a></li>
  <li><a href="zend.soap.wsdl.html">WSDL Accessor</a></li>
  <li class="active"><a href="zend.soap.autodiscovery.html">AutoDiscovery</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>